<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="/js/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/chosen/chosen.jquery.js"></script>
    <script>
        $(function () {

            var strategyId= getParams().strategyId;
            var user = window.sessionStorage.getItem("user");
            //页面加载完, 查询当前收藏数
            $.get('/strategys/count/'+strategyId,function (data) {
                 $("#count").html(data)
             })
            if(user){
                $.get('/strategys/get/'+strategyId,function (data) {
                    if(data.data){
                        $("#collectBtn").html("取消收藏")

                    }else{
                        $("#collectBtn").html("加入收藏")
                    }
                })
            }
            //收藏攻略
            $("#collectBtn").click(function () {
                $.post('/strategys/collect',{strategyId:strategyId},function (data) {

                    console.log(data);
                    if(!data.success){
                        $(document).dialog({
                            type : 'confirm',
                            style: 'IOS',
                            titleText: data.msg,
                            content: '是否马上登陆',
                            buttons: [
                                {
                                    name: '登陆',
                                    callback: function() {
                                        window.parent.location.href="/login.html";
                                    }
                                }, {
                                    name: '返回',
                                    callback: function() {

                                    }
                                }
                            ]
                        });

                    }else{
                        //点击收藏按钮之后, 再次查询收藏数
                        $.get('/strategys/count/'+strategyId,function (data) {
                            $("#count").html(data)
                        })

                        $("#collectBtn").html(data.data)
                    }
                })
            })
            if(strategyId){
                //渲染标题
                $.get('/strategys/'+strategyId,function (data) {
                    $('.strategies').renderValues(data);
                });
                //大家都在看
                $.get('/strategys/'+strategyId+'/travels',function (data) {
                    $('.hot').renderValues({list:data},{
                        setHref:function (item, value) {
                            $(item).attr("href",$(item).data('href')+value);
                        }
                    });
                });

                //目录的回显
                $.get('/strategys/'+strategyId+'/catalogs',function (data) {
                    var index=1;
                    $('.catalogs').renderValues({list:data},{
                        //每次循环
                        setName:function (item, value) {
                            if(index<10) {
                                $(item).html("0"+index + "/" + value);
                            }else {
                                $(item).html(index + "/" + value);
                            }
                            index+=1;
                        },
                        setHref:function (item, value) {
                            $(item).attr("href",$(item).data('href')+value);
                        }
                    })
                })
                //评论页面的内容显示
                var merge =[];
                $.get('/strategyComment/'+strategyId,function (data) {

                    $('.tag').renderValues({list:data});
                    $('#comment').renderValues({list:data},{
                        'getStar':function(item,value) {
                            var starhtml='';
                            var unStarhtml='';
                            for(var i=0; i<value; i++){
                                starhtml+= '<i class="fa fa-star"></i>';
                            }
                            for( i=0; i<5-value ; i++){
                                unStarhtml+= '<i class="fa fa-star-o"></i>';
                            }

                            $(item).html(starhtml+unStarhtml);
                        },
                        setHref:function (item, value) {
                            $(item).attr("href",$(item).data('href')+value);
                        }

                    })
                    //图片点击
                    $(".comment-img img").click(function () {
                        $(document).dialog({
                            titleShow: false,
                            overlayClose: true,
                            content: '<div style="text-align: center;"><img width="100%" src="'+$(this).attr('src')+'"></div>'
                        });
                    })
                })
                //点评
                $('#commentBtn').click(function () {
                    window.location.href="/mine/addComment.html?strategyId="+strategyId;
                })
                //查询功能
                $.get('strategys', {pageSize:0}, function (data) {
                    $('#strategies').append("<option value='-1'>-寻找攻略-</option>")
                    var op = "";
                    $.each(data, function (index, item) {
                        op+= "<option value='"+item.id+"'>"+item.title+"</option>"
                    })

                    $("#strategies").append(op);
                    $("#strategies").chosen({
                        no_results_text: "无相关地区!",//搜索无结果时显示的提示
                        disable_search_threshold: 5,//选项小于5时不显示搜索框
                        search_contains:true,   //关键字模糊搜索，设置为false，则只从开头开始匹配
                        allow_single_deselect:true, //是否允许取消选择
                        max_selected_options:6  //当select为多选时，最多选择个数
                    })
                    $('.chosen-select').on('change', function(e, params) {
                        console.log(params);
                        window.location.href="/strategyCatalogs.html?strategyId="+params.selected
                    });
                })

            }
        })

    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title" render-html="title"></h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span id="count"> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div render-loop="list">
                <a data-href="travelContent.html?id=" render-fun="setHref" render-key="list.id">
                <button class="btn" render-html="list.title"></button>
                </a>
            </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-fun="setName" render-key="list.name"></h6>
                    <div render-loop="list.details">
                        <a data-href="strategyDetails.html?id=" render-fun="setHref" render-key="list.details.id">
                        <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div render-loop="list">
                <span render-html="list.tag.name"></span>
            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a href="userProfiles.html?id="  >
                            <img class="rounded-circle"
                                 render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName">
                            <span render-html="list.user.nickName" ></span>
                        </p>
                        <span class="comment-star" render-key="list.starNum" render-fun="getStar">

                        </span>
                        <span class="comment-date" render-html="list.createTime"></span>
                        <div class="comment-content">
                            <a data-href="/mine/strategyComment.html?id=" render-fun="setHref" render-key="list.id" >
                                <p render-html="list.content"></p>
                            </a>
                        </div>

                        <ul class="comment-img" render-loop="list.imgUrlss" >
                            <li>
                                <img render-src="list.imgUrlss.self">
                            </li>
                        </ul>

                        <div class="d-flex icon">
                            <a data-href="/mine/strategyComment.html?id=" render-fun="setHref" render-key="list.id" >
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                                <i class="fa fa-thumbs-o-up" > <span >0</span> </i>
                            </a>
                        </div>

                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="operation">
    <button class="btn" id="collectBtn" >加入收藏</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>